<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/commons/taglibs.jsp"%>
<%@ include file="/static/commons/meta.jsp"%>
<%@ include file="/static/commons/jquery-easyui.jsp"%>
<html >
	 <head>
 		<title>${title }</title>
 		<link rel="stylesheet" href="${ctx }/static/styles/basic/basic.css" />
		<link rel="stylesheet" href="${ctx }/static/styles/frame/main.css" />
		<link rel="stylesheet" href="${ctx }/static/styles/frame/searchBtn.css" />
		<link rel="stylesheet" href="${ctx }/static/styles/frame/searchCondition.css" />
	    <!-- js -->
 		<script type="text/javascript" src="${ctx}/static/scripts/check_all.js"></script>
 		<script type="text/javascript" src="${ctx}/static/scripts/set_select.js"></script>
 		<script type="text/javascript" src="${ctx}/static/scripts/waiting.js"></script>
 		<script type="text/javascript" src="${ctx}/static/scripts/crud.js"></script>
 		<script type="text/javascript" src="${ctx}/static/scripts/common.js"></script>
 		<script type="text/javascript" src="${ctx}/static/scripts/util.js"></script>
	</head>
  <body onload="init()">
		<form action="${ctx}/myRepair/list" method="post">
  			<input type="hidden" name="RequestVerificationToken" value="${RequestVerificationToken}" />
			<div class="width_100 group_box">
				<div class="group_search width_100">
					<vvise:select id="custId" name="p_custId" sqlname="getCust" displayText="用户单位" ifSearch="true"/>
		            <vvise:select id="deviceType" name="p_deviceType" sqlname="getCodeData" sqlparam="device_type" displayText="类型" ifSearch="true"/>
		            <vvise:searchInput id="orderId" name="p_orderId" displayText="订单号" />
			        <div class="clear_both"></div>
				</div>
				<vvise:funMenu menuId="${menuId}" />
			</div>
        </form>
        <div class="listFrame">
        	<iframe name="listFrame" id="listFrame" frameBorder="0"
				scrolling="auto" style="width: 100%;height:100%;"></iframe>
        </div>
	</body>
	<script type="text/javascript">
  		var headers = {};
		headers['__RequestVerificationToken'] = "${RequestVerificationToken}";
			//回车事件
		document.onkeydown = keyKistener;
		function keyKistener(e){
			e = e ? e:event;
			if(e.keyCode == 13){
				try{
					search();
				}catch(e){}
			}
		}
		function init(){
			set_iframe_h();
			$(window).resize(function(){
				set_iframe_h();
			});
			search();
			$('.easyui-combobox').combobox();
		}
		//设置ifream 高度
		function set_iframe_h(){
			var win_height  = $(window).height();
			var func_line_h = $('.group_box').outerHeight(true);
			var list_height = win_height - func_line_h;
			$('.listFrame').css('height',list_height-10);
		}
		
		function search(){
			waiting();
			document.forms[0].target = "listFrame";
			document.forms[0].submit();
		}
		
		function view(custId, deviceType, orderId){
			var pp = parent;
			doView("检查仪器信息",pp.width3+400, 500,"${ctx}/myRepair/viewList?p_custId="+custId+"&p_deviceType="+deviceType+"&p_orderId="+orderId);
		}
		
		function recondition(){
			var pp = parent;
			var ecForm = listFrame.document.all.ec;
			if(!checkSelect(ecForm.id,false,'检修单'))
				return;
			var id = get_checkbox_value(ecForm.id);
			var ids = id.split('@@');
			pp.openWindow("检修单",pp.width3,500,"${ctx}/myRepair/edit?p_custId="+ids[0]+"&p_deviceType="+ids[1]+"&p_orderId="+ids[2],[{
				text:'确认维修',
				iconCls:'icon-ok',
				id:'btn0',
				handler:function(){
					saveRecord(0);
				}
			},{
				text:'确认维修并检测',
				iconCls:'icon-ok',
				id:'btn1',
				handler:function(){
					saveRecord(1);
				}
			},{
				text:'取消',
				iconCls:'icon-no',
				handler:function(){
					pp.closeWindow();
				}
			}]);
			pp.$('#winDiv #btn1').hide();
		}
		
		function saveRecord(type){
			var pp = parent;
			var editFrame = pp.winFrame;
			var flag = editFrame.validForm();
			
			var equId = editFrame.$('#equId').val();
			var deviceType = editFrame.$('#deviceType').val();
			var orderId=editFrame.$('#orderId').val();
			var gasTypeIds=editFrame.$('#gasTypeId').val();
			var originalRecord=editFrame.$("#originalRecord").val();

			var originalRecordArray=originalRecord.split(",");

			var gasTypeIdArray=[];
            if(gasTypeIds!=undefined && gasTypeIds!=null && gasTypeIds!=""){
                gasTypeIdArray=gasTypeIds.split(",");
            }
debugger;
			if(flag){
//				pp.$.messager.confirm('操作提示','确定要保存吗？',function(r){
//				    if (r){
				   	    $.ajax({
							cache: false,
							type: "POST",
							headers: headers,
							url:'${ctx}/myRepair/save',
							data:editFrame.$('#editForm').serialize(),
							async: false,
						    error: function(request) {
					            pp.$.messager.alert('操作提示',"操作失败！","error");
						    },
						    success: function(data) {
						    	if(data && "success" == data){
						    	    if(gasTypeIdArray.length>1){

						    	        var msgdiv='<div class="panel window messager-window" style="display: block; width: 278px; left: 285.5px; top: 225px; z-index: 9019; position: absolute;"><div class="panel-header panel-header-noborder window-header" style="width: 278px;"><div class="panel-title" style="">填写原始记录单</div><div class="panel-tool"></div></div><div id="messDiv" class="messager-body panel-body panel-body-noborder window-body" title="" style="width: 258px; height: auto;"><div>Content_Area</div><div style="clear:both;"></div><div class="messager-button"><a href="javascript:void(0)" class="l-btn" style="margin-left: 10px;"><span class="l-btn-left"><span class="l-btn-text" onclick="javascript:$(this).parent().parent().parent().parent().parent().remove()">关闭</span></span></a></div></div></div>';

                                        var msgStr="";
                                        for(var i=0;i<gasTypeIdArray.length;i++){
                                            if(originalRecordArray[i]==null || originalRecordArray[i]==" " || originalRecordArray[i]==""){
                                                msgStr+="<a href='javascript:void(0)' name='gasClickName' gasTypeId='"+gasTypeIdArray[i]+"' equId='"+equId+"' deviceType='"+deviceType+"' orderId='"+orderId+"' sort='"+i+"' onclick=\"doDetection('"+equId+"','"+deviceType+"','"+orderId+"','"+gasTypeIdArray[i]+"','"+i+"')\">填写 "+gasTypeIdArray[i]+" 原始单据</a><br>";
                                            }
                                        }


                                        msgdiv=msgdiv.replace("Content_Area",msgStr);

										$("body").append(msgdiv);

//

                                        pp.closeWindow();

                                    }else{
                                        doDetection(equId, deviceType,orderId,gasTypeIds,-1);
                                    }




					         	}else{
					         		pp.$.messager.alert('操作提示',"操作失败！","error");
					         	}
						    }
						});
//					}
//				});
			}
		}
		
		function doDetection(equId, deviceType,orderId,gasTypeId,sort){
			var pp = parent;
			if(deviceType==3){
				pp.openWindow("气体检测仪设备检测",pp.width3+200,700,"${ctx}/myRepair/toDetect?equId="+equId+"&deviceType="+deviceType+"&orderId="+orderId+"&gasTypeId="+gasTypeId+"&sort="+sort,[
                    {
                        text:'检定',
                        iconCls:'icon-ok',
                        handler:function(){
                            parent.$("#winDiv3").find("iframe")[0].contentWindow.createKeyObj();
                        }
                    },{
                    text:'保存',
                    iconCls:'icon-ok',
                    handler:function(){
//                        saveTemplateData(pp);
                        saveTemplateData(parent.$("#winDiv3"));
                    }
                },{
                    text:'取消',
                    iconCls:'icon-no',
                    handler:function(){
                        pp.closeWindow('winDiv3');
                    }
                }],'','winDiv3');
			}else{
//				deviceType = (1==deviceType)?'气瓶':'空呼'
				pp.openWindow(deviceType+"设备检测",pp.width3+200,700,"${ctx}/myRepair/toDetect?equId="+equId+"&deviceType="+deviceType+"&orderId="+orderId,[
                    {
                        text:'检定',
                        iconCls:'icon-ok',
                        handler:function(){
                            //chooseParts(index_);
//                    alert('dfdf');
                            parent.$("#winDiv2").find("iframe")[0].contentWindow.createKeyObj();
                        }
                    },{
					text:'保存',
					iconCls:'icon-ok',
					handler:function(){
						//chooseParts(index_);
//						alert('dfdf')
                        saveTemplateData(parent.$("#winDiv2"));
					}
				},{
					text:'取消',
					iconCls:'icon-no',
					handler:function(){
						pp.closeWindow('winDiv2');
					}
				}],'','winDiv2');
			}
		}
				
		
		function detection(){
			doDetection('142',3);
		}
		
		
		function saveTemplateData(windowDiv) {
            debugger;
//			alert(1);
            var pp = parent;
            var str=windowDiv.find("iframe").contents().find("body").html()
			var orderId=windowDiv.find("iframe").contents().find("#orderId").val();
			var equId=windowDiv.find("iframe").contents().find("#equId").val();
			var sort=windowDiv.find("iframe").contents().find("#sortId").val();
			var scopeId=windowDiv.find("iframe").contents().find("#scopeId").val();

            var  keyObj= windowDiv.find("iframe")[0].contentWindow.createKeyObj();


            pp.$.messager.confirm('操作提示','确定要保存吗？',function(r){
                if (r){
                    $.ajax({
                        cache: false,
                        type: "POST",
                        headers: headers,
                        url:'${ctx}/template/saveTemplate',
                        data:{"tempData":str,"orderId":orderId,"equId":equId,"sort":sort,"scopeId":scopeId,"keyObj":JSON.stringify(keyObj),"isPass":keyObj.isPass,"type":keyObj.type,"checkUser":keyObj.hyyid,"verifiedUser":keyObj.ydyid,"verify":keyObj.jdyj},
                        async: false,
                        error: function(request) {
                            pp.$.messager.alert('操作提示',"操作失败！","error");
                        },
                        success: function(data) {
                            if(data && "success" == data){
                                pp.$.messager.alert('操作提示',"保存成功！","info",function(){

                                    pp.closeWindow();
                                });
                            }else{
                                pp.$.messager.alert('操作提示',"操作失败！","error");
                            }
                        }
                    });
                }
            });


        }


		
		</script>
</html>